package codeTop;

public class q328 {
    public ListNode oddEvenList(ListNode head) {
        ListNode pre1 = new ListNode();
        ListNode pre2 = new ListNode();
        ListNode p = head;
        ListNode p1 = pre1,p2 = pre2;
        int num = 0;
        while (p != null) {
            if (++num % 2 == 1) {
                p1.next = p;
                p1 = p1.next;
            }else {
                p2.next = p;
                p2 = p2.next;
            }
            p = p.next;
        }
        p1.next = pre2.next;
        p2.next = null;
        return pre1.next;
    }
}
